@extends('admin.master')

@section('top')
	<div class="top-breadcrumb pull-left">{!! Breadcrumbs::render('user') !!}</div>
	<div class="top-btn-group pull-right">
		<a href="{{ route('admin.user.create') }}" class="btn btn-primary">添加用户</a>
	</div>
@endsection

@section('content')
<div class="section-search mb10">
	{!! Form::model($where, ['method'=>'get', 'class'=>'form-inline']) !!}
	<div class="form-group">
		<label class="control-label">员工姓名：</label>
		{!! Form::text('name', null, ['class'=>'form-control len200', 'placeholder'=>'姓名']) !!}
	</div>
	<div id="department" class="inline-block">
		<div class="form-group">
			<label class="control-label">区域：</label>
			<select name="region_id" class="form-control autosize region"></select>
		</div>
		<div class="form-group">
			<label class="control-label">部门：</label>
			<select name="department_id" class="form-control autosize department"></select>
		</div>
	</div>
	<button type="submit" class="btn btn-default">查询</button>
{!! Form::close() !!}
</div>
{!! Form::open(['url'=>'admin/user']) !!}
	<table class="table table-hover table-list">
		<thead>
			<tr>
				<th width="65" class="text-center">ID</th>
				<th>用户名</th>
				<th>状态</th>
				<th>用户组</th>
				<th>区域</th>
				<th>部门</th>
				<th>姓名</th>
				<th>手机号</th>
				<th>邮箱</th>
				<th>QQ</th>
				<th class="text-right">操作</th>
			</tr>
		</thead>
		<tbody>
		@if (!$data->isEmpty())
			@foreach ($data as $value)
				<tr {!! $value->status ? '' : 'class="danger"' !!}>
					<td class="text-center">{{ $value->id }}</td>
					<td>{{ $value->username }}</td>
					<td>
						@if (!$value->status)
							<strong class="text-danger">已冻结</strong>
						@endif
					</td>
					<td>{{ $value->group->name }}</td>
					<td>{{ $departmentsById[$value->region_id]['name'] or '' }}</td>
					<td>{{ $departmentsById[$value->department_id]['name'] or '' }}</td>
					<td>{{ $value->name }}</td>
					<td>{{ $value->phone }}</td>
					<td>{{ $value->email }}</td>
					<td>{{ $value->qq }}</td>
					<td class="text-right">
						<div class="toolbar">
							<a href="javascript:void(0)" data-href="{{ url('admin/password/reset-force/'.$value->id) }}" class="btn-link password-reset">重置密码</a>
							<span class="text-explode ">|</span>
							<a href="{{ route('admin.user.edit', $value->id) }}" class="btn-link">修改</a>
							<span class="text-explode ">|</span>
							<a href="javascript:void(0);" data-id="{{ $value->id }}" class="btn-link delete-item">删除</a>
						</div>
					</td>
				</tr>
			@endforeach
		@endif
		</tbody>
	</table>
	@if (!$data->isEmpty())
	<table class="table table-footer">
		<tfoot>
			<tr>
				<td>
					<div class="pagination-box">
						<div class="pull-right">
							<div class="pagination-info">共有{{ $data->total() }}条， 每页显示：20条</div>
							{!! $data->appends(request()->except('page'))->render() !!}
						</div>
					</div>				
				</td>
			</tr>
		</tfoot>
	</table>
	@else
	<div class="simple-none-data text-center">
		<i class="fa fa-exclamation-circle text-size-20 text-muted" style="vertical-align: middle"></i> 
		<span class="text-size-14 inline-block ml5">没有查询到符合条件的记录</span>
	</div>
	@endif
{!! Form::close() !!}
@endsection

@section('foot')
<script src="{{ url('js/bootstrap.min.js') }}"></script>
<script src="{{ url('js/department.js') }}"></script>
<script type="text/javascript">
	var departments = {!! json_encode($departmentsTree, JSON_UNESCAPED_UNICODE) !!};
	var where = {!! $where !!};

	department.init({
		regions: departments,
		departments: departments,
		where: where
	}).make();

	// 密码重置
	$('.password-reset').on('click', function() {
		var href = $(this).data('href');
		$.get(href, function(data) {
			if (data != '') {
				swal('失败！', data, 'error');
			} else {
				swal('成功！', '密码重置成功！', 'success');
			}

			return false;
		});
	});
	</script>	
@endsection
